﻿#ifndef DLGHISTORY_H
#define DLGHISTORY_H

#include <QDialog>
#include <QSettings>
#include <QStringListModel>
#include <QMenu>
#include <QAction>

#include "datastruct.h"

namespace Ui {
class DlgHistory;
}

class DlgHistory : public QDialog
{
    Q_OBJECT

public:
    explicit DlgHistory(QSettings* settings, QList<ChannelDescription> channelDescriptionList, QWidget *parent = nullptr);
    ~DlgHistory() override;

protected:
    void keyPressEvent(QKeyEvent *event) override;

private:
    void initUI();
    void init();
    void loadStyle(const QString& stylePath);
    void readDataFile(const QString& filename, QList<QByteArray>& bufferList);
    void exportCsvFile(const QString& filename, const QList<QByteArray>& bufferList);

private:
    Ui::DlgHistory *ui;

    // 历史记录数据模型
    QStringListModel m_historyModel;

    // 右键菜单: 导出
    QMenu* m_menu;

private:
    // INI配置文件
    QSettings* m_settings;

    // 通道描述列表
    QList<ChannelDescription> m_channelDescriptionList;

    // 存盘路径
    QString m_savePath;


private slots:
    void onQueryAll();
    void onQuery();
    void onExport();
    void onHistoryContextMenu(const QPoint &pos);
    void onItemDoubleClicked(const QModelIndex &modelIndex);
    void onOk();
};

#endif // DLGHISTORY_H
